/*
 * copyright (c) 2013 Blaise-Florentin Collin
 *
 * This file is part of astroDCAM.
 *
 * AstroAviBrowser is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License v3
 * as published by the Free Software Foundation
 *
 * AstroAviBrowser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * v3 along with AstroAviBrowser; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA
 */

///
/// \file QAstroCameraTab.hpp
/// \brief Camera tab widget
///

#ifndef _QASTROCAMERATAB_HPP_
#define _QASTROCAMERATAB_HPP_

// Qt includes
#include <QComboBox>
#include <QPushButton>
#include <QTimer>

// C++ app includes
#include "dc1394error.hpp"
#include "dc1394bus.hpp"
#include "dc1394camera.hpp"
#include "frame.hpp"

// Qt app includes
#include "QAstroTab.hpp"

///
/// \class QAstroCameraTab
/// \brief Camera tab widget
///
class QAstroCameraTab : public QAstroTab {
   Q_OBJECT
   public :
      /// Main constructor
      QAstroCameraTab(dc1394bus* bus, QWidget* p=0);
      /// Main destructor
      ~QAstroCameraTab();
      /// Build GUI
      int buildGUI();
   private :
      // attributes
      dc1394bus* mainBus; ///< The ieee1394 bus
      dc1394camera* mainCam; ///< The current camera
      std::vector<dc1394cameraId> cameraList; ///< The current camera list
      std::vector<dc1394mode> modeList; ///< The supported modes list
      std::vector<dc1394rate> rateList; ///< The supported frame rates list

      // GUI stuff
      bool guiReady;
      QComboBox* cameraChooser;
      QPushButton* busReset;
      QComboBox* modeChooser;
      QComboBox* rateChooser;
      QPushButton* captureButton;

      // private methods
      void resetCameraList();
      void resetModeList();
      void resetRateList();
      dc1394error setCam(uint64_t cam);
      dc1394error setMode(int mode);
      dc1394error setRate(int rate);
      dc1394error startCapture();
      dc1394error stopCapture();

      // frame capture stuff
      QTimer* frameTimer; ///< timer for frame grabbing

      // current frame
      frame* currentFrame; ///< current frame

   private slots :
      void resetBus();
      void changeCam(int index);
      void changeMode(int index);
      void changeRate(int index);
      void changeCapture(bool checked);
      void grabFrame();
};

#endif
